<?php
// +----------------------------------------------------------------------
// | 有理想的地方，地狱都是天堂。
// +----------------------------------------------------------------------
// | Copyright @ df81.com 版权所有
// +----------------------------------------------------------------------
// | 作者: 南国老符 邮箱：1062129401@qq.com
// +----------------------------------------------------------------------

namespace app\admin\controller;
use think\facade\Db;
use think\facade\View;

class Sitemap extends Base{
    // 站点地图
    public function index(){
        // 是否有开启的城市分站
        $defaultLang = config('lang.default_lang');
        $cityWhere[] = ['signid','=',1]; $cityWhere[] = ['is_domain','=',1]; $cityWhere[] = ['lang','=',$defaultLang];
        $citySite = Db::name('area')->where($cityWhere)->whereNotNull('bind_domain')->field('abbreviation,bind_domain')->select();
        View::assign('citySite',$citySite);
        
    	if(!request()->isPost()){
            // 站点地图文件
            $xml = $txt = $html = $rss = '';
            if(file_exists(public_path().'sitemap.xml')) $xml = 'sitemap.xml';
            if(file_exists(public_path().'sitemap.txt')) $txt = 'sitemap.txt';
            if(file_exists(public_path().'sitemap.html')) $html = 'sitemap.html';
            if(file_exists(public_path().'rss.xml')) $rss = 'rss.xml';
            View::assign('xml',$xml);
            View::assign('txt',$txt);
            View::assign('html',$html);
            View::assign('rss',$rss);
            
            

            return view();
        }else{
            // 参数
            $type = input('type');

            // 生成sitemap.xml
            if(in_array('xml', $type)){
                $sitemap = $this->make('xml');
                file_put_contents('sitemap.xml', $sitemap);
            }
            // 生成sitemap.txt
            if(in_array('txt', $type)){
                $sitemap = $this->make('txt');
                file_put_contents('sitemap.txt', $sitemap);
            }
            // 生成sitemap.html
            if(in_array('html', $type)){
                $sitemap = $this->make('html');
                file_put_contents('sitemap.html', $sitemap);
            }
            // 生成rss.xml
            if(in_array('rss', $type)){
                $sitemap = $this->make('rss');
                file_put_contents('rss.xml', $sitemap);
            }
            
            return json(['code' => 200, 'msg' => lang('c_success'), 'data' => '']);
        }
    }

    // 生成站点地图
    public function make($type = 'xml'){
        $url_array = $this->url();
        
        // 地图类型
        switch ($type) {
            // sitemap.xml
            case 'xml':
                $sitemap =  '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
                $sitemap .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'.PHP_EOL;
                // 首页
                foreach ($url_array['home'] as $home) {
                    $sitemap .= '   <url>'.PHP_EOL;
                    $sitemap .= '       <loc>'.$home['url'].'</loc>'.PHP_EOL;
                    $sitemap .= '       <priority>'.input('home_priority').'</priority>'.PHP_EOL;
                    $sitemap .= '       <lastmod>'.gmdate('Y-m-d\TH:i:s+08:00', time()).'</lastmod>'.PHP_EOL;
                    $sitemap .= '       <changefreq>'.input('home_frequency').'</changefreq>'.PHP_EOL;
                    $sitemap .= '   </url>'.PHP_EOL;
                }
                // 内容页
                foreach ($url_array['detail'] as $detail) {
                    $sitemap .= '   <url>'.PHP_EOL;
                    $sitemap .= '       <loc>'.$detail['url'].'</loc>'.PHP_EOL;
                    $sitemap .= '       <priority>'.input('detail_priority').'</priority>'.PHP_EOL;
                    $sitemap .= '       <lastmod>'.gmdate('Y-m-d\TH:i:s+08:00', $detail['time']).'</lastmod>'.PHP_EOL;
                    $sitemap .= '       <changefreq>'.input('detail_frequency').'</changefreq>'.PHP_EOL;
                    $sitemap .= '   </url>'.PHP_EOL;
                }
                // 列表页
                foreach ($url_array['list'] as $list) {
                    $sitemap .= '   <url>'.PHP_EOL;
                    $sitemap .= '       <loc>'.$list['url'].'</loc>'.PHP_EOL;
                    $sitemap .= '       <priority>'.input('list_priority').'</priority>'.PHP_EOL;
                    $sitemap .= '       <lastmod>'.gmdate('Y-m-d\TH:i:s+08:00', time()).'</lastmod>'.PHP_EOL;
                    $sitemap .= '       <changefreq>'.input('list_frequency').'</changefreq>'.PHP_EOL;
                    $sitemap .= '   </url>'.PHP_EOL;
                }
                // 分类页
                foreach ($url_array['sort'] as $sort) {
                    $sitemap .= '   <url>'.PHP_EOL;
                    $sitemap .= '       <loc>'.$sort['url'].'</loc>'.PHP_EOL;
                    $sitemap .= '       <priority>'.input('sort_priority').'</priority>'.PHP_EOL;
                    $sitemap .= '       <lastmod>'.gmdate('Y-m-d\TH:i:s+08:00', time()).'</lastmod>'.PHP_EOL;
                    $sitemap .= '       <changefreq>'.input('sort_frequency').'</changefreq>'.PHP_EOL;
                    $sitemap .= '   </url>'.PHP_EOL;
                }
                // 关键词首页
                foreach ($url_array['keyword_home'] as $keyword_home) {
                    $sitemap .= '   <url>'.PHP_EOL;
                    $sitemap .= '       <loc>'.$keyword_home['url'].'</loc>'.PHP_EOL;
                    $sitemap .= '       <priority>'.input('keyword_priority').'</priority>'.PHP_EOL;
                    $sitemap .= '       <lastmod>'.gmdate('Y-m-d\TH:i:s+08:00', time()).'</lastmod>'.PHP_EOL;
                    $sitemap .= '       <changefreq>'.input('keyword_frequency').'</changefreq>'.PHP_EOL;
                    $sitemap .= '   </url>'.PHP_EOL;
                }
                // 关键词列表页
                foreach ($url_array['keyword_list'] as $keyword_list) {
                    $sitemap .= '   <url>'.PHP_EOL;
                    $sitemap .= '       <loc>'.$keyword_list['url'].'</loc>'.PHP_EOL;
                    $sitemap .= '       <priority>'.input('keyword_list_priority').'</priority>'.PHP_EOL;
                    $sitemap .= '       <lastmod>'.gmdate('Y-m-d\TH:i:s+08:00', time()).'</lastmod>'.PHP_EOL;
                    $sitemap .= '       <changefreq>'.input('keyword_list_frequency').'</changefreq>'.PHP_EOL;
                    $sitemap .= '   </url>'.PHP_EOL;
                }
                if(config('global.url.bind_lang') == 1 and config('global.url.city_site') == 1){
                    // 城市分站首页
                    foreach ($url_array['city_home'] as $city_home) {
                        $sitemap .= '   <url>'.PHP_EOL;
                        $sitemap .= '       <loc>'.$city_home['url'].'</loc>'.PHP_EOL;
                        $sitemap .= '       <priority>'.input('city_priority').'</priority>'.PHP_EOL;
                        $sitemap .= '       <lastmod>'.gmdate('Y-m-d\TH:i:s+08:00', $city_home['time']).'</lastmod>'.PHP_EOL;
                        $sitemap .= '       <changefreq>'.input('city_frequency').'</changefreq>'.PHP_EOL;
                        $sitemap .= '   </url>'.PHP_EOL;
                    }
                }
                $sitemap .= '</urlset>';
                break;
            // sitemap.txt
            case 'txt':
                $sitemap = '';
                // 首页
                foreach ($url_array['home'] as $home) {
                    $sitemap .= $home['url'].PHP_EOL;
                }
                // 内容页
                foreach ($url_array['detail'] as $detail) {
                    $sitemap .= $detail['url'].PHP_EOL;
                }
                // 列表页
                foreach ($url_array['list'] as $list) {
                    $sitemap .= $list['url'].PHP_EOL;
                }
                // 分类页
                foreach ($url_array['sort'] as $sort) {
                    $sitemap .= $sort['url'].PHP_EOL;
                }
                // 关键词首页
                foreach ($url_array['keyword_home'] as $keyword_home) {
                    $sitemap .= $keyword_home['url'].PHP_EOL;
                }
                // 关键词列表页
                foreach ($url_array['keyword_list'] as $keyword_list) {
                    $sitemap .= $keyword_list['url'].PHP_EOL;
                }
                if(config('global.url.bind_lang') == 1 and config('global.url.city_site') == 1){
                    // 城市分站首页
                    foreach ($url_array['city_home'] as $city) {
                        $sitemap .= $city['url'].PHP_EOL;
                    }
                }
                break;
            // sitemap.html
            case 'html':
                $sitemap =  '<!doctype html>'.PHP_EOL;
                $sitemap .= '<html>'.PHP_EOL;
                $sitemap .= '<head>'.PHP_EOL;
                $sitemap .= '    <meta charset="utf-8">'.PHP_EOL;
                $sitemap .= '    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">'.PHP_EOL;
                $sitemap .= '    <title>html '.lang('v_sitemap').'</title>'.PHP_EOL;
                $sitemap .= '    <style>div{margin:0 auto; width:100%; font-size:.875rem;}ul{padding:0 2%;}ul,li{list-style:none;}li{float:left; width:46%; margin:5px 2%; padding:0 0 10px 0; border-bottom:1px solid #eee;}a{text-decoration:none;}li a{float:left; width:70%; color:#333;}li span{float:left; width:30%; text-align:right; color:#999;}.title{margin:10px 4% 0; width:92%; padding:0 0 10px; font-size:1.5rem; color:#f00; border-bottom:1px solid #eee;}.w-100{width:100%;}@media (max-width: 767px){li{float:left; width:100%;}li a{float:left; width:100%;}li span{float:left; width:100%; text-align:left;}}</style>'.PHP_EOL;
                $sitemap .= '</head>'.PHP_EOL;
                $sitemap .= '<body>'.PHP_EOL;
                $sitemap .= '   <div class="title">HTML Sitemap</div>'.PHP_EOL;
                $sitemap .= '   <div class="w-100">'.PHP_EOL;
                $sitemap .= '       <ul>'.PHP_EOL;
                // 首页
                foreach ($url_array['home'] as $home) {
                    $sitemap .= '           <li><a href="'.$home['url'].'" title="'.$home['title'].'" target="_blank">'.$home['title'].'</a><span>'.gmdate('Y-m-d\TH:i:s+08:00', time()).'</span></li>'.PHP_EOL;
                }
                // 内容页
                foreach ($url_array['detail'] as $detail) {
                    $sitemap .= '           <li><a href="'.$detail['url'].'" title="'.$detail['title'].'" target="_blank">'.$detail['title'].'</a><span>'.gmdate('Y-m-d\TH:i:s+08:00', $detail['time']).'</span></li>'.PHP_EOL;
                }
                // 列表页
                foreach ($url_array['list'] as $list) {
                    $sitemap .= '           <li><a href="'.$list['url'].'" title="'.$list['title'].'" target="_blank">'.$list['title'].'</a><span>'.gmdate('Y-m-d\TH:i:s+08:00', time()).'</span></li>'.PHP_EOL;
                }
                // 分类页
                foreach ($url_array['sort'] as $sort) {
                    $sitemap .= '           <li><a href="'.$sort['url'].'" title="'.$sort['title'].'" target="_blank">'.$sort['title'].'</a><span>'.gmdate('Y-m-d\TH:i:s+08:00', time()).'</span></li>'.PHP_EOL;
                }
                // 关键词首页
                foreach ($url_array['keyword_home'] as $keyword_home) {
                    $sitemap .= '           <li><a href="'.$keyword_home['url'].'" title="'.$keyword_home['title'].'" target="_blank">'.$keyword_home['title'].'</a><span>'.gmdate('Y-m-d\TH:i:s+08:00', time()).'</span></li>'.PHP_EOL;
                }
                // 关键词列表页
                foreach ($url_array['keyword_list'] as $keyword_list) {
                    $sitemap .= '           <li><a href="'.$keyword_list['url'].'" title="'.$keyword_list['title'].'" target="_blank">'.$keyword_list['title'].'</a><span>'.gmdate('Y-m-d\TH:i:s+08:00', time()).'</span></li>'.PHP_EOL;
                }
                if(config('global.url.bind_lang') == 1 and config('global.url.city_site') == 1){
                    // 城市分站首页
                    foreach ($url_array['city_home'] as $city) {
                        $sitemap .= '           <li><a href="'.$city['url'].'" title="'.$city['title'].'" target="_blank">'.$city['title'].'</a><span>'.gmdate('Y-m-d\TH:i:s+08:00', time()).'</span></li>'.PHP_EOL;
                    }
                }
                $sitemap .= '       </ul>'.PHP_EOL.'   </div>'.PHP_EOL.'</body>'.PHP_EOL.'</html>';
                break;
            // rss.xml
            case 'rss':
                $sitemap =  '<?xml version="1.0"?>'.PHP_EOL;
                $sitemap .= '<rss version="2.0">'.PHP_EOL;
                $sitemap .= '   <channel>'.PHP_EOL;
                // 首页
                foreach ($url_array['home'] as $key => $home) {
                    if(strpos($home['url'],'www.') !== false){
                        $sitemap .= '       <title>'.htmlspecialchars(strip_tags($home['title'])).'</title>'.PHP_EOL;
                        $sitemap .= '       <link>'.$home['url'].'</link>'.PHP_EOL;
                        $sitemap .= '       <description>'.htmlspecialchars(strip_tags($home['description'])).'</description>'.PHP_EOL;
                    }else{
                        $sitemap .= '       <item>'.PHP_EOL;
                        $sitemap .= '           <title>'.htmlspecialchars(strip_tags($home['title'])).'</title>'.PHP_EOL;
                        $sitemap .= '           <link>'.$home['url'].'</link>'.PHP_EOL;
                        $sitemap .= '           <description>'.htmlspecialchars(strip_tags($home['description'])).'</description>'.PHP_EOL;
                        $sitemap .= '       </item>'.PHP_EOL;
                    }
                }
                // 内容页
                foreach ($url_array['detail'] as $detail) {
                    $sitemap .= '       <item>'.PHP_EOL;
                    $sitemap .= '           <title>'.htmlspecialchars(strip_tags($detail['title'])).'</title>'.PHP_EOL;
                    $sitemap .= '           <link>'.$detail['url'].'</link>'.PHP_EOL;
                    $sitemap .= '           <description>'.htmlspecialchars(strip_tags($detail['description'])).'</description>'.PHP_EOL;
                    $sitemap .= '           <pubDate>'.gmdate('Y-m-d\TH:i:s+08:00', $detail['time']).'</pubDate>'.PHP_EOL;
                    $sitemap .= '       </item>'.PHP_EOL;
                }
                // 列表页
                foreach ($url_array['list'] as $list) {
                    $sitemap .= '       <item>'.PHP_EOL;
                    $sitemap .= '           <title>'.htmlspecialchars(strip_tags($list['title'])).'</title>'.PHP_EOL;
                    $sitemap .= '           <link>'.$list['url'].'</link>'.PHP_EOL;
                    $sitemap .= '           <description>'.htmlspecialchars(strip_tags($list['description'])).'</description>'.PHP_EOL;
                    $sitemap .= '       </item>'.PHP_EOL;
                }
                // 分类页
                foreach ($url_array['sort'] as $sort) {
                    $sitemap .= '       <item>'.PHP_EOL;
                    $sitemap .= '           <title>'.htmlspecialchars(strip_tags($sort['title'])).'</title>'.PHP_EOL;
                    $sitemap .= '           <link>'.$sort['url'].'</link>'.PHP_EOL;
                    $sitemap .= '           <description>'.htmlspecialchars(strip_tags($sort['description'])).'</description>'.PHP_EOL;
                    $sitemap .= '       </item>'.PHP_EOL;
                }
                // 关键词首页
                foreach ($url_array['keyword_home'] as $keyword_home) {
                    $sitemap .= '       <item>'.PHP_EOL;
                    $sitemap .= '           <title>'.htmlspecialchars(strip_tags($keyword_home['title'])).'</title>'.PHP_EOL;
                    $sitemap .= '           <link>'.$keyword_home['url'].'</link>'.PHP_EOL;
                    $sitemap .= '           <description>'.htmlspecialchars(strip_tags($keyword_home['description'])).'</description>'.PHP_EOL;
                    $sitemap .= '       </item>'.PHP_EOL;
                }
                // 关键词列表页
                foreach ($url_array['keyword_list'] as $keyword_list) {
                    $sitemap .= '       <item>'.PHP_EOL;
                    $sitemap .= '           <title>'.htmlspecialchars(strip_tags($keyword_list['title'])).'</title>'.PHP_EOL;
                    $sitemap .= '           <link>'.$keyword_list['url'].'</link>'.PHP_EOL;
                    $sitemap .= '           <description>'.htmlspecialchars(strip_tags($keyword_list['description'])).'</description>'.PHP_EOL;
                    $sitemap .= '       </item>'.PHP_EOL;
                }
                if(config('global.url.bind_lang') == 1 and config('global.url.city_site') == 1){
                    // 城市分站首页
                    foreach ($url_array['city_home'] as $city) {
                        $sitemap .= '       <item>'.PHP_EOL;
                        $sitemap .= '           <title>'.htmlspecialchars(strip_tags($city['title'])).'</title>'.PHP_EOL;
                        $sitemap .= '           <link>'.$city['url'].'</link>'.PHP_EOL;
                        $sitemap .= '           <description>'.htmlspecialchars(strip_tags($city['description'])).'</description>'.PHP_EOL;
                        $sitemap .= '       </item>'.PHP_EOL;
                    }
                }
                $sitemap .= '   </channel>'.PHP_EOL.'       </rss>'.PHP_EOL;
                break;
        }

        return $sitemap;
    }

    // 返回url
    public function url(){
        $siteurl = request()->domain().'/'; $configDomainArray = config('app.domain_bind');
        $url_category = config('global.url.category'); $url_view = config('global.url.view');
        $url_root = config('global.url.root'); $url_root_module = config('global.url.root_module');
        // url 开始
        $list_array = $sort_array = $detail_array = $keyword_home = $keyword_list = array();
        $language = Db::name('language')->where('signid',1)->field('mulu,isdefault,viewtitle')->select();
        foreach ($language as $langRs) {
            /*语言站点首页网址 开始*/
            // 未绑定域名
            if(empty($configDomainArray)){
                // 非默认语言
                if($langRs['isdefault'] != 1) $siteurl .= $langRs['mulu'].'/';
            }else{
                // 非默认语言
                if($langRs['isdefault'] != 1){
                    foreach ($configDomainArray as $bindDomain => $bindLang){
                        // 当前语言和绑定语言一致
                        if($langRs['mulu'] == $bindLang){
                            $siteurl = request()->scheme().'://'.$bindDomain.'/';
                        }
                    }
                }else{
                    // 找出默认语言绑定的域名
                    $defaultDomainArray = array_keys($configDomainArray,config('app.default_app'));
                    if(!in_array('www.'.request()->rootDomain(),$defaultDomainArray)){
                        $siteurl = request()->scheme().'://'.$defaultDomainArray[0].'/';
                    }
                }
                
            }
            /*语言站点首页网址 结束*/
            
            // 首页
            $siteRs = Db::name('site')->where('lang',$langRs['mulu'])->field('title,keyword,description,company,city_title,city_keyword,city_description')->find();
            $home[] = array('title'=>$siteRs['title'],'url'=>$siteurl,'time'=>time(),'description'=>$siteRs['description']);
            // 默认语言，城市分站用
            if($langRs['isdefault'] == 1){
                $cityRs = $siteRs;
                $cityNavUrl = $siteurl;
            }
            
            // 列表页
            $module = Db::name('module')->where('disabled',1)->where('lang',$langRs['mulu'])->field('lang,urlroute,tabledir,seotitle,description')->select();
            foreach ($module as $mRs) {
                $list_array[] = array('title'=>str_replace('[city]','',$mRs['seotitle']),'url'=>$siteurl.$mRs['urlroute'].'/','time'=>time(),'description'=>str_replace('[city]','',$mRs['description']));
            }
            
            // 分类页
            $sort = Db::name('sort')->where('signid',1)->where('lang',$langRs['mulu'])->field('lang,urlroute,id,parentid,tabledir,title,seotitle,description')->select();
            foreach ($sort as $sRs) {
                switch ($url_category) {
                    case 0:
                        $loc = $sRs['urlroute'];
                        break;
                    case 1:
                        // 第一步：是否为顶级分类
                        if($sRs['parentid'] == 0){
                            $loc = $sRs['urlroute'];
                            break;
                        }else{
                            // 第二步：查找父级并返回
                            $loc = getParentStr($sRs['id'], 'sort', '/', 'id,parentid,urlroute', 'urlroute');
                            break;
                        }
                    case 2:
                        $module_urlroute = Db::name('module')->where('lang',$sRs['lang'])->where('tabledir',$sRs['tabledir'])->value('urlroute');
                        $loc = $module_urlroute.'/'.$sRs['urlroute'];
                        break;
                    case 3:
                        $module_urlroute = Db::name('module')->where('lang',$sRs['lang'])->where('tabledir',$sRs['tabledir'])->value('urlroute');
                        // 第一步：是否为顶级分类
                        if($sRs['parentid'] == 0){
                            $loc = $module_urlroute.'/'.$sRs['urlroute'];
                            break;
                        }else{
                            // 第二步：查找父级并返回
                            $loc = $module_urlroute.'/'.getParentStr($sRs['id'], 'sort', '/', 'id,parentid,urlroute', 'urlroute');
                            break;
                        }
                }
                $title = $sRs['title'];
                if(!empty($sRs['seotitle'])) $title = $sRs['seotitle'];
                $sort_array[] = array('title'=>$title,'url'=>$siteurl.$loc.'/','time'=>time(),'description'=>$sRs['description']);
            }
            
            // 内容页
            foreach ($module as $mRs) {
                $table = Db::name($mRs['tabledir'])->where('signid',1)->where('lang',$langRs['mulu'])->field('id,urlroute,lang,addtime,title,seotitle,addtime,description')->order('addtime desc')->select();
                foreach ($table as $tRs) {
                    /* 禁用：内容页置于根目录，或：启用但不是当前模型 */
                    if($url_root == 0 or ($url_root == 1 and $url_root_module != $mRs['tabledir'])){
                        // 模型
                        switch ($url_view) {
                            case 0:
                                $loc = $mRs['urlroute'].'/'.$tRs['urlroute'].'.html';
                                break;
                            case 1:
                                $loc = $mRs['urlroute'].'/'.$tRs['id'].'.html';
                                break;
                        }
                    }
                    /* 启用：内容页置于根目录，且是当前模型 */
                    if($url_root == 1 and $url_root_module == $mRs['tabledir']){
                        switch ($url_view) {
                            case 0:
                                $loc = $tRs['urlroute'].'.html';
                                break;
                            case 1:
                                $loc = $tRs['id'].'.html';
                                break;
                        }
                    }
                    $title = $tRs['title'];
                    if(!empty($tRs['seotitle'])) $title = $tRs['seotitle'];
                    $detail_array[] = array('title'=>$title,'url'=>$siteurl.$loc,'time'=>$tRs['addtime'],'description'=>strip_tags($tRs['description']));
                }
            }
            
            // 关键词首页
            $keyword_home[] = array('title'=>$langRs['viewtitle'].' '.lang('v_label').' '.lang('v_map'),'url'=>$siteurl.'tags/keyword.html','time'=>time(),'description'=>'');
            
            // 关键词列表页
            $keyword = Db::name('keyword')->where('signid',1)->where('lang',$langRs['mulu'])->field('lang,urlroute,keyword')->select();
            foreach ($keyword as $kRs) {
                $loc = 'tags/'.$kRs['urlroute'].'/';
                $keyword_list[] = array('title'=>$kRs['keyword'],'url'=>$siteurl.$loc,'time'=>time(),'description'=>$kRs['description']);
            }
        }
        
        /*城市分站 开始*/
        $defaultLang = config('lang.default_lang');
        $cityWhere[] = ['signid','=',1]; $cityWhere[] = ['is_domain','=',1]; $cityWhere[] = ['lang','=',$defaultLang];
        $citySite = Db::name('area')->where($cityWhere)->whereNotNull('bind_domain')->field('abbreviation,bind_domain')->select();
        
        $city_home = array();
        // 城市分站导航
        if(!empty($citySite)){
            if(!empty($cityRs['keyword'])){
                $cityNavTitle = '';
                $cityKeywordArray = explode('，',$cityRs['keyword']);
                foreach ($cityKeywordArray as $cityKw){
                    $cityNavTitle .= $cityKw.lang('v_corporation').'-';
                }
                $cityNavTitle .= $cityRs['company'];
            }else{
                $cityNavTitle = $cityRs['company'];
            }
            $city_home[] = array('title'=>$cityNavTitle,'url'=>$cityNavUrl.'area/sitemap.html','time'=>time(),'description'=>$cityRs['description']);
        }
        // 城市分站首页
        foreach ($citySite as $city){
            $cityTitle = str_replace('[city]',$city['abbreviation'],$cityRs['city_title']);
            $cityUrl = request()->scheme().'://'.$city['bind_domain'].'/';
            $cityDescription = str_replace('[city]',$city['abbreviation'],$cityRs['city_description']);
            $city_home[] = array('title'=>$cityTitle,'url'=>$cityUrl,'time'=>time(),'description'=>$cityDescription);
        }
        /*城市分站 结束*/

        // 返回url数组
        return array('home' => $home, 'list' => $list_array, 'sort' => $sort_array, 'detail' => $detail_array, 'keyword_home' => $keyword_home, 'keyword_list' => $keyword_list, 'city_home' => $city_home);
    }
}